<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/background/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/background/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/background/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/background/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/background/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/background/js/xadmin.js"></script>
</head>
<body>
<div class="x-body">
    <form id="ggg" class="layui-form">
        <c:if test="${tda==0}">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>动物类型
                </label>
                <div class="layui-input-inline">
                    <select id="classFlag" name="anTypeId" class="species">
                        <c:forEach items="${allAnimalType}" var="y" varStatus="row">
                            <option value="${y.tyId}">${y.tyName}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
        </c:if>
        <c:if test="${tda!=0}">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>动物类型
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="${animalType.tyId}" readonly="readonly"  name="anTypeId" required lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
        </c:if>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>动物名字
            </label>
            <div class="layui-input-inline">
                <input type="text" id="className" name="anName" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>动物年龄
            </label>
            <div class="layui-input-inline">
                <input type="text" name="anAge" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>性格描述
            </label>
            <div class="layui-input-inline">
                <input type="text" name="anFormation" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>照片
            </label>
            <div class="layui-input-inline">
                <input type="file" name="Img" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button  class="layui-btn" type="button" lay-filter="add" onclick="addAnimal()" lay-submit="">
                增加
            </button>
        </div>
    </form>
</div>
<script type="text/javascript">


    layui.use(['form','layer','jquery'], function() {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        window.addAnimal=function () {
            $ = layui.jquery;
            var layer = layui.layer;
            var formData=new FormData($("#ggg")[0]);
            //监听提交
            $.ajax({
                type:'POST',
                url:'addAnimal',
                data:formData,
                async: false,
                contentType: false,
                processData: false,
                //等待返回值
                success:function(result){
                    if(result=="SUCCESS"){
                        layer.confirm('添加成功',{icon: 6},function(index){
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新我的 双亲页面 classobjlist.jsp
                            window.parent.location.reload();                        })
                    }
                    else{
                        layer.alert(result,{title:"添加失败"});
                    }
                }
            });
            return false;
        }
    })

</script>
</body>
</html>